package cn.kbyue.exceptiondemo.common.validate;

import cn.kbyue.exceptiondemo.dto.DateForm;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author xlang
 * @date 2023/4/4 13:10
 */
public class DateSequenceCheckValidator implements ConstraintValidator<DateSequenceCheck, DateForm> {

    @Override
    public boolean isValid(DateForm dateForm, ConstraintValidatorContext constraintValidatorContext) {
        if (dateForm.getStartDate() == null || dateForm.getEndDate() == null) {
            return true;
        }
        return dateForm.getEndDate().isAfter(dateForm.getStartDate());
    }


}
